#include "..\headers\ListOf.h"

typedef int ElemType;

typedef struct LNodeList {
  ElemType data;
  struct LNodeList *next;
} LNodeList, *LinkList;

// 链表初始化
int InitList(LinkList L) {
  L = (LinkList)malloc(sizeof(LNodeList));
  if (!L) exit(-1);
  L->next = NULL;
  return OK;
}

int Length(LinkList &L) {
  LinkList p;
  p = L->next;

  int cnt = 0;
  while (p) {
    cnt++;
    p = p->next;
  }
  return cnt;
}

int FindKth(LinkList &L, int k, ElemType &e) {
  LinkList p;
  p = L->next;

  int cnt = 1;
  while (p && cnt < k) {
    p = p->next;
    cnt++;
  }
  if (cnt == k && p) {
    printf("你找的第%d个数为%d", k, p->data);
    e = p->data;
    return OK;
  }
  printf("你查找的数不存在");
  return ERROR;
}
